// test_rag_after_fix.js - 修复后测试RAG功能
const dotenv = require('dotenv');
const path = require('path');
const axios = require('axios');

// 加载环境变量
dotenv.config({ path: path.resolve(__dirname, '.env') });

async function testRAG() {
    try {
        console.log("测试RAG搜索功能...");
        
        // 发送搜索请求
        const response = await axios.post('http://localhost:3000/api/rag/search', {
            query: "赵云",
            k: 4
        }, {
            headers: {
                'Authorization': 'Bearer your-test-token-here' // 需要提供有效的认证令牌
            }
        });
        
        console.log("✓ RAG搜索请求成功");
        console.log("响应状态:", response.status);
        console.log("结果数量:", response.data.length);
        
        if (response.data.length > 0) {
            console.log("第一个结果预览:", response.data[0].pageContent?.substring(0, 100) + "...");
        }
        
    } catch (error) {
        if (error.response) {
            console.error("RAG搜索请求失败:", error.response.status, error.response.statusText);
            console.error("响应数据:", error.response.data);
        } else {
            console.error("请求失败:", error.message);
        }
    }
}

testRAG();